package org.sundatagroup.aurora.monitor.entity;

import org.sundatagroup.aurora.core.entity.IJsonEntity;
import org.sundatagroup.aurora.monitor.entity.player.PlayerParam;
import org.sundatagroup.aurora.monitor.entity.pojo.PlayList;
import org.sundatagroup.aurora.show.entity.status.IStatusEntity;

import com.google.gson.JsonObject;

/**
 * <p>与展示屏捆在一起的数据（监控区）
 * </p>
 * 
 * @author Zdream
 * @date 2018-05-28
 * @since 0.2.0
 */
public class ScreenEntry implements IJsonEntity {
	
	public final String sid;
	
	/**
	 * 是否在连接状态
	 */
	private boolean connect = true;

	/**
	 * 状态, 不可能为空<br>
	 * 这个可以理解为播放单个工程的状态
	 */
	private IStatusEntity status;
	
	/**
	 * <p>播放列表状态
	 * <p>不允许改动
	 */
	private final PlayerParam param = new PlayerParam();
	
	/**
	 * @param status
	 *   初始状态
	 * @throws NullPointerException
	 *   当 status = null 时
	 */
	public ScreenEntry(IStatusEntity status) {
		this.sid = status.getSid();
		this.status = status;
	}

	public synchronized IStatusEntity getStatus() {
		return status;
	}

	/**
	 * 设置 status
	 * @param status
	 * @throws NullPointerException
	 *   当 status = null 时
	 */
	public synchronized void setStatus(IStatusEntity status) {
		if (status == null) {
			throw new NullPointerException("status : IStatusEntity = null");
		}
		this.status = status;
	}

	public PlayList getPlayList() {
		return param.getPlayList();
	}

	public void setPlayList(PlayList playList) {
		param.setPlayList(playList);
	}

	public PlayerParam getParam() {
		return param;
	}

	public boolean isConnect() {
		return connect;
	}

	public void setConnect(boolean connect) {
		this.connect = connect;
	}

	@Override
	public synchronized JsonObject toJson() {
		JsonObject jo;
		
		if (status != null) {
			jo = status.toJson().getAsJsonObject();
		} else {
			jo = new JsonObject();
			jo.addProperty("sid", sid);
		}
		jo.add("player", param.toJson());
		jo.addProperty("connect", connect);
		
		return jo;
	}
	
}
